﻿<Window 
    x:Class="TFSBuildMonitor.Presentation.Views.ShellWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:vm="clr-namespace:TFSBuildMonitor.Applications.ViewModels" 
    mc:Ignorable="d" 
    Title="{Binding Title}" 
    Icon="{StaticResource ApplicationIcon}" 
    Width="640" 
    Height="480" 
    d:DataContext="{d:DesignInstance vm:ShellViewModel}">

    <Grid Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="32" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ToolBar Grid.Row="0">
            <ToolBarPanel Orientation="Horizontal">
                <Button Name="btnConnect" Height="24" Width="70" Content="Connect" Margin="2,0" Command="{Binding ConnectCommand}" />
                <Button Name="btnDisconnect" Height="24" Width="70" Content="Disconnect" Margin="2,0" Command="{Binding DisconnectCommand}" />
                <ComboBox Name="cbControllers" Height="24" Width="300" Margin="2,0" ItemsSource="{Binding Controllers}" SelectedItem="{Binding Path=SelectedController}" IsSynchronizedWithCurrentItem="True" />
                <ProgressBar Height="10" Width="100" IsIndeterminate="True" Visibility="{Binding ProgressVisibility}"  Margin="10,0,0,0"/>
            </ToolBarPanel>
        </ToolBar>

        <TabControl Name="tabMain" Grid.Row="1" Width="Auto" Height="Auto" SelectedIndex="{Binding TabIndex}">

            <TabItem Header="Queue">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <Button x:Name="btnExportQueue" Height="24" Width="60" Content="Export" Margin="0,0,0,13" Command="{Binding QueuedExportCommand}" VerticalAlignment="Bottom" />
                    </StackPanel>

                    <DataGrid Grid.Row="1" x:Name="grdQueue" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding Path=Queue}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Status}" Header="Status" />
                            <DataGridTextColumn Binding="{Binding Path=Definition}" Header="Project/Definition" />
                            <DataGridTextColumn Binding="{Binding Path=Reason}" Header="Reason" />
                            <DataGridTextColumn Binding="{Binding Path=Priority}" Header="Priority" />
                            <DataGridTextColumn Binding="{Binding Path=Triggered, StringFormat=\{0:yyyy-MM-dd HH:mm:ss zzz\}}" Header="Triggered" />
                            <DataGridTextColumn Binding="{Binding Path=Position}" Header="Position" />
                            <DataGridTextColumn Binding="{Binding Path=Requester}" Header="Requester" />
                            <DataGridTextColumn Binding="{Binding Path=AgentSettings}" Header="AgentSettings" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Finished">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <StackPanel Orientation="Vertical">
                            <Label Content="Days back" VerticalAlignment="Top" HorizontalAlignment="Left" Height="26" />
                            <TextBox Name="edtDaysFinished" Height="24" Width="60" Margin="2,0" VerticalContentAlignment="Center" Text="{Binding Path=DaysFinished}" />
                        </StackPanel>
                        <Button Name="btnRefreshFinished" Height="24" Width="60" Content="Refresh" Margin="2,0" Command="{Binding FinishedRefreshCommand}" VerticalAlignment="Bottom" />
                        <Button Name="btnExportFinished" Height="24" Width="60" Content="Export" Margin="2,0" Command="{Binding FinishedExportCommand}" VerticalAlignment="Bottom" />
                    </StackPanel>

                    <DataGrid Grid.Row="1" x:Name="grdFinished" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding Path=Finished}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding BuildNumber}" Header="BuildNumber" />
                            <DataGridTextColumn Binding="{Binding Definition}" Header="Project/Definition" />
                            <DataGridTextColumn Binding="{Binding Status}" Header="Status" />
                            <DataGridTextColumn Binding="{Binding Started, StringFormat=\{0:yyyy-MM-dd HH:mm:ss zzz\}}" Header="Started" />
                            <DataGridTextColumn Binding="{Binding Ended, StringFormat=\{0:yyyy-MM-dd HH:mm:ss zzz\}}" Header="Ended" />
                            <DataGridTextColumn Binding="{Binding Duration, StringFormat=\{0:N2\}}" Header="Duration (Min)" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Total">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <StackPanel Orientation="Vertical">
                            <Label Content="Days back" VerticalAlignment="Top" HorizontalAlignment="Left" Height="26" />
                            <TextBox Name="edtDaysTotal" Height="24" Width="60" Margin="2,0" VerticalContentAlignment="Center" Text="{Binding Path=DaysTotals}" />
                        </StackPanel>
                        <Button Name="btnRefreshTotals" Height="24" Width="60" Content="Refresh" Margin="2,0" Command="{Binding TotalsRefreshCommand}" VerticalAlignment="Bottom" />
                        <Button Name="btnExportTotals" Height="24" Width="60" Content="Export" Margin="2,0" Command="{Binding TotalsExportCommand}" VerticalAlignment="Bottom" />
                    </StackPanel>
                    <DataGrid Grid.Row="1" x:Name="grdTotal" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding Totals}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Project}" Header="Project" />
                            <DataGridTextColumn Binding="{Binding Path=Count}" Header="Number of builds" />
                            <DataGridTextColumn Binding="{Binding Path=Duration, StringFormat=\{0:N2\}}" Header="Total duration (Hrs)" />
                            <DataGridTextColumn Binding="{Binding Path=Avg, StringFormat=\{0:N2\}}" Header="Avg duration (Hrs)" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Last Check-in">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <Button x:Name="btnGetLastCheckIns"  Margin="0,0,6,0" Height="24" Width="110" Content="Get last check-ins" Command="{Binding GetLastCheckInsCommand}"  RenderTransformOrigin="0.506,-0.333" ></Button>

                    </StackPanel>
                    <DataGrid x:Name="GrdLastCheckins" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding LastCheckIns}"
                              Grid.Row="1">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Project}" Header="Project" />
                            <DataGridTextColumn Binding="{Binding Path=LastCheckIn}" Header="Last check-in" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="All builds" HorizontalAlignment="Left" Width="66">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <Button x:Name="btnGetAllBuilds"  Margin="0,13,6,13" Height="24" Width="110" Content="Get all builds" Command="{Binding GetAllBuildsCommand}"  RenderTransformOrigin="0.506,-0.333" />
                        <StackPanel Orientation="Vertical"/>
                    </StackPanel>
                    <DataGrid x:Name="GrdAllBuilds" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding AllBuilds}"
                              Grid.Row="1">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=TeamProject}" Header="TeamProject" />
                            <DataGridTextColumn Binding="{Binding Path=BuildNumber}" Header="BuildNumber" />
                            <DataGridTextColumn Binding="{Binding Path=Status}" Header="Status" />
                            <DataGridTextColumn Binding="{Binding Path=DropLocationRoot}" Header="DropLocationRoot" />
                            <DataGridTextColumn Binding="{Binding Path=DropLocation}" Header="DropLocation" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Project Admins" HorizontalAlignment="Left" Width="93" Margin="-2,-2,-25,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="56" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="6,0,6,6">
                        <Button x:Name="btnGetAllProjectAdmins"  Margin="0,13,6,13" Height="24" Width="130" Content="Get all project admins" Command="{Binding GetAllProjectAdminsCommand}"  RenderTransformOrigin="0.506,-0.333" />
                        <StackPanel Orientation="Vertical"/>
                    </StackPanel>
                    <DataGrid x:Name="GrdAllProjectAdmins" AutoGenerateColumns="False" VerticalScrollBarVisibility="Visible" Padding="0,10,0,0" ItemsSource="{Binding AllProjectAdmins}"
                              Grid.Row="1">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=TeamProject}" Header="TeamProject" />
                            <DataGridTextColumn Binding="{Binding Path=ProjectAdmins}" Header="Project Admins" />
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
            
        </TabControl>

    </Grid>
</Window>
